package com.example.administrator.yunniuusedcar.activity;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.adapter.MainAdapter;
import com.example.administrator.common.base.BaseActivity;
import com.example.administrator.yunniuusedcar.adapter.ShopInfon_JBAdapter;
import com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment.GuiGeInfoFragment;
import com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment.JiBenInfoFragment;
import com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment.PingJiaFragment;
import com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment.TuWenInfoFragment;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.mineModular.ShoopingCarActivity;
import com.example.administrator.yunniuusedcar.mineModular.YuYueActivity;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.RanCarXiangQingBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

// 商品详情  (Tablayout + viewPager + Fragment)

public class CommodityDetailsActivity extends BaseActivity {


    @BindView(R.id.tab_commodityInfo)
    TabLayout tabCommodityInfo;
    @BindView(R.id.vp_commodityInfp)
    ViewPager vpCommodityInfp;
    @BindView(R.id.IV_erroPAGE)
    ImageView IVErroPAGE;
    @BindView(R.id.LL_keFuZiXun)
    LinearLayout LLKeFuZiXun;
    @BindView(R.id.iv_shuoCang)
    ImageView ivShuoCang;
    @BindView(R.id.LL_JiaRuShouCang)
    LinearLayout LLJiaRuShouCang;
    @BindView(R.id.bt_JiaRuShoopCar)
    Button btJiaRuShoopCar;
    @BindView(R.id.bt_LiJiGuoMai)
    Button btLiJiGuoMai;
    private ImageView iv_backs;
    private ImageView ivJiSuan;


    @Override
    public int getLayoutRes() {
        return R.layout.activity_commodity_details;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        iv_backs = findView(R.id.iv_back);
        iv_backs.setOnClickListener(new View.OnClickListener() {    //返回图片
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        initViewPaer();
        initTabLayout();
        intiFV();

        //loadDatas();
    }



    private void intiFV() {
        ivJiSuan = findView(R.id.iv_JiSuan);

    }


    String[] titless = {"基本信息","图文信息","规格参数","评价"};
    private void initViewPaer() {
        List<Fragment> fragmens = new ArrayList<>();
        fragmens.add(new JiBenInfoFragment());
        fragmens.add(new TuWenInfoFragment());
        fragmens.add(new GuiGeInfoFragment());
        fragmens.add(new PingJiaFragment());

        MainAdapter mainAdapters = new MainAdapter(getSupportFragmentManager(),fragmens,titless);

        vpCommodityInfp.setAdapter(mainAdapters);

    }

    private void initTabLayout() {
        tabCommodityInfo.setupWithViewPager(vpCommodityInfp);
    }




    @Override
    public void initListener() {

    }

    ArrayList listDatas = new ArrayList();
    @Override
    public void initData() {

        ShopInfon_JBAdapter shopInfonJbAdapter = new ShopInfon_JBAdapter(this,listDatas);
    }
    @OnClick({R.id.LL_keFuZiXun, R.id.LL_JiaRuShouCang,R.id.iv_JiSuan, R.id.bt_JiaRuShoopCar, R.id.bt_LiJiGuoMai})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.LL_keFuZiXun:    // 客服咨询
                Intent intent = new Intent(CommodityDetailsActivity.this, YuYueActivity.class);
                startActivity(intent);
                break;
            case R.id.LL_JiaRuShouCang:   // 加入收藏
                break;
            case R.id.bt_JiaRuShoopCar:   // 加入购物车
            startActivity(new Intent(CommodityDetailsActivity.this, ShoopingCarActivity.class));
                break;
            case R.id.bt_LiJiGuoMai:    // 立即购买
                break;
            case R.id.iv_JiSuan:        //购车计算
                startActivity(new Intent(CommodityDetailsActivity.this,BuyCarCountActivity.class));
                break;

        }
    }

//        String id = getActivity().getStringExtra("RanCarid");
//    Intent intent1 = Intent.getIntent().getSerializableExtra("RanCarID");

//    Intent intent = getIntent();
//    String trm = intent.getStringExtra("RanCarid");
//    int resultID = Integer.valueOf(trm); //汽车列表id
//
//    private void loadDatas() {
////
//        String ul = IHttpService.HOST_URL + "Car/getcarInfo";    // 随机汽车 详情
//                                                                                                                //String.valueOf(resultID)
//        OkHttpUtils.post().url(ul).addParams("sign",IHttpService.SignVal).addParams("car_id", "24").build()
//                .execute(new StringCallback() {
//                    @Override
//                    public void onError(Call call, Exception e, int id) {
//                        Global.showToast("RanCarInfo ERRor" + e);
//                    }
//
//                    @Override
//                    public void onResponse(String response, int id) {
//                        System.out.println("-----====----------A" + response.toString());
//
//                        RanCarXiangQingBean ranCarInfoBean = new Gson().fromJson(response, RanCarXiangQingBean.class);
//                        if(ranCarInfoBean.code==1){
//                            listDatas.add(ranCarInfoBean);
//                    }
//                }
//                });
//    }
}
